package cn.edu.tsinghua.weibo.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ContentFilter {
	
	private final static String REGEX = "@[A-Za-z0-9\u4e00-\u9fa5_-]+";
	private final static String LEFT = "<a href=\"http://127.0.0.1:8080/n/";
	private final static String CENTER = "\">";
	private final static String RIGHT = "</a>";
	
	public static String getFiltratedContent(String rawContent) {
		Matcher matcher = Pattern.compile(REGEX).matcher(rawContent);
		StringBuffer stringBuffer = new StringBuffer();
		while (matcher.find()) {
			String keytmp = matcher.group();
			String defaultFormatKey = LEFT + keytmp.substring(1) + CENTER + keytmp + RIGHT;
			matcher.appendReplacement(stringBuffer, defaultFormatKey);
		}
		matcher.appendTail(stringBuffer);
		return stringBuffer.toString();
	}
	
	public static void main(String[] args) {
		String string = "asdf@asdf“@;s阿斯顿:ASDFW @@-_@@-阿斯顿   啊@1____-----23";
		System.out.println(getFiltratedContent(string));
	}
	
}
